package com.czxttkl.xml;

import java.io.InputStream;

import org.xmlpull.v1.XmlPullParser;
import android.util.Log;
import android.util.Xml;

public class PullXmlService {

	public static MeasureTask getXml(InputStream inputStream) throws Exception {
		MeasureTask tempTask = null;
		XmlPullParser pullParser = Xml.newPullParser();
		pullParser.setInput(inputStream, "UTF-8");
		int event = pullParser.getEventType();
		while (event != XmlPullParser.END_DOCUMENT) {
			switch (event) {
			case XmlPullParser.START_DOCUMENT:
				;
				break;
			case XmlPullParser.START_TAG:
				if ("task".equals(pullParser.getName())) {
					tempTask = new MeasureTask();
					tempTask.setId(Integer.valueOf(pullParser.getAttributeValue(0)));
				}
				if (tempTask != null) {
					if ("phonetype".equals(pullParser.getName()))
						tempTask.setPhoneType(pullParser.nextText());
					if ("networktype".equals(pullParser.getName()))
						tempTask.setNetworkType(pullParser.nextText());
				}
				break;
			case XmlPullParser.END_TAG:
				if ("task".equals(pullParser.getName())) {
					return tempTask;
				}
				break;
			}
			event = pullParser.next();
			
		}
		return null;
		

	}
}
